package com.teemor.blog.controller;

import com.teemor.blog.api.ICommentApiService;
import com.teemor.blog.bean.condition.TbCommentCondition;
import com.teemor.blog.bean.dto.output.comment.QryCommentODTo;
import com.teemor.blog.bean.dto.output.comment.QryCommentsODTo;
import com.teemor.blog.bean.entity.TbComment;
import com.teemor.blog.bean.dto.input.comment.AddCommentIDTo;
import com.teemor.blog.bean.dto.input.comment.QryCommentsIDTo;
import com.teemor.blog.bean.dto.input.comment.UpdCommentIDTo;
import com.teemor.blog.service.ICommentService;
import java.util.List;

import com.teemor.common.bean.utils.BeanConvertor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: zhoulk
 * @Description: 原子服务API接口实现
 * @date: 2019/11/26 14:50:14
 */
@RestController
public class CommentController implements ICommentApiService {
    @Autowired
    private ICommentService iCommentService;

    @Override
    public QryCommentODTo qryComment(@PathVariable Integer commentId) {
        return BeanConvertor.convertBean(iCommentService.qryCommentById(commentId), QryCommentODTo.class);
    }

    @Override
    public int countComment(@RequestBody QryCommentsIDTo inParam) {
        TbCommentCondition condition = BeanConvertor.convertBean(inParam, TbCommentCondition.class);
        return iCommentService.countComment(condition);
    }

    @Override
    public List<QryCommentsODTo> qryComments(@RequestBody QryCommentsIDTo inParam) {
        TbCommentCondition condition = BeanConvertor.convertBean(inParam, TbCommentCondition.class);
        return BeanConvertor.convertBeanList(iCommentService.qryComments(condition), QryCommentsODTo.class);
    }

    @Override
    public void updComment(@RequestBody UpdCommentIDTo inParam) {
        TbComment tbComment = BeanConvertor.convertBean(inParam, TbComment.class);
        iCommentService.updCommentById(tbComment);
    }

    @Override
    public void addComment(@RequestBody AddCommentIDTo inParam) {
        TbComment tbComment = BeanConvertor.convertBean(inParam, TbComment.class);
        iCommentService.addComment(tbComment);
    }
}